//
//  SetData.m
//  OST
//
//  Created by mac on 13-7-11.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "CommonData.h"
#import "Common.h"

@interface CommonData ()

@end

@implementation CommonData
@synthesize url;
@synthesize justCommand;
@synthesize newValue;

-(id)initWidthUrl:(NSString *)_zid
{
    if (self = [super init]) {
        self.url = _zid;
        newValue = 0 ;
    }
    return self;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    if (justCommand) {
        [self doneLoadData:[NSDictionary dictionaryWithObjectsAndKeys:[reciveData lowercaseString] ,@"result",[NSNumber numberWithInt:newValue],@"newValue", nil]];
    }else{
        NSArray *items = [reciveData componentsSeparatedByString:@"\n"];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        for (NSString *item in items) {
            NSArray *values = [item componentsSeparatedByString:@"="];
            if (values && [values count]>1) {
                [dict setValue:[values objectAtIndex:1] forKey:[[values objectAtIndex:0]lowercaseString]  ];
            }
        }
        
        [self doneLoadData:dict];
    }
}

-(void)doneLoadData:(id)data
{
    [super doneLoadData:data];
}

-(void)reLoadData
{
    self.httpRequest = [Common createHTTPRequest:url delegate:self];
    [self.httpRequest startAsynchronous];
}



@end
